﻿namespace Pottery.FrontEnd.Helpers
{
    using System.Globalization;
    using System.Threading;
    using Pottery.Module.Infractructure;
    using Pottery.Web.Helpers;

    public static class ApplicationCulture
    {
        #region Public Properties

        public static string Culture
        {
            get
            {
                string culture = CookieUtil.GetCookieValue(ModuleConstants.COOKIE_LANGUAGE_NAME);
                if (string.IsNullOrEmpty(culture))
                    culture = ModuleConstants.LANGUAGE_EN;

                return culture;
            }
            set
            {
                if (CookieUtil.CookieExists(ModuleConstants.COOKIE_LANGUAGE_NAME))
                    CookieUtil.DeleteCookie(ModuleConstants.COOKIE_LANGUAGE_NAME);

                CookieUtil.CreateCookie(ModuleConstants.COOKIE_LANGUAGE_NAME, value, null);
            }
        }

        #endregion

        #region Public Methods

        public static void SetCulture()
        {
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(ApplicationCulture.Culture);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Thread.CurrentThread.CurrentUICulture.Name);
        }

        #endregion
    }
}